define(function(require){
    'use strict';

    var
        _ = require('underscore'),
        $ = require('jquery'),
        Utils = require('core/utils'),
        Base = require('../_base/app');

    require('datetimepicker');

    return Base.extend({

        template: require('tpl!./app.template'),

        ui: {
            input: '.js-name-input',
            save: '.js-save',
            cancel: '.js-cancel'
        },

        events: {
            'click @ui.cancel': 'close',
            'click @ui.save': 'save',
            'keypress @ui.input': 'handleNameInputKeypress'
        },


        serializeData: function() {
            var data = this.options.data || {};

            return _.extend({
                max_input_length: 0
            }, data)
        },

        save: function() {
            var value = this.ui.input.val();
            if(_.isFunction(this.options.callback)) {
                this.options.callback(value);
            }
            this.close();
        },

        handleNameInputKeypress: function(e) {
            if(e.keyCode === Utils.keyCode.ENTER) {
                this.save();
            }
        }

    });
});
